//
//  SIWelcomeView.swift
//  SinaImiate
//
//  Created by xiaoming on 16/7/4.
//  Copyright © 2016年 GoodJob. All rights reserved.
//

import UIKit
import SDWebImage

class SIWelcomeView: UIView {

    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var tipLabel: UILabel!
    
    @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
    
    class func welcomeView() -> SIWelcomeView {
        
        let nib = UINib(nibName: "SIWelcomeView", bundle: nil)
        
        let v = nib.instantiate(withOwner: nil, options: nil)[0] as! SIWelcomeView
        
        v.frame = UIScreen.main().bounds
        
        return v
        
    }
    
    override func awakeFromNib() {
        
        guard let urlSring = SINetworkTools.shared.userAccount.avatar_large,
            url = URL(string: urlSring) else {
                return
        }
        
        iconView.sd_setImage(with: url, placeholderImage: #imageLiteral(resourceName: "avatar_default_big"))
        
        
        
    }
    
    
    
    override func didMoveToWindow() {
        super.didMoveToWindow()
        ///保证视图移动到窗口后,所有的控件位置固定
        self.layoutIfNeeded()
        
        ///用运行时或者代码设置圆形图像
//        iconView.layer.cornerRadius  = iconView.bounds.width * 0.5
//        iconView.layer.masksToBounds = true
//        
        bottomConstraint.constant = bounds.size.height - 200
        
        
        UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0, options: .curveLinear, animations: {
            
            self.layoutIfNeeded()
            
            }) { (_) in
                
                UIView.animate(withDuration: 1.0, animations: { 
                     self.tipLabel.alpha = 1.0
                    }, completion: { (_) in
                        self.removeFromSuperview()
                })
        }
        
    }
}
